/**
 * Created with BlueStream
 * Date: 13. 6. 3
 * Time: 오후 3:28
 * Writer: 강석민
 */

var panel1Div;
var textNode;
var totalCountInput;
var totalCount;
var btn_startButton;
var btn_stopButton;
var color;

var timeID = 0;

window.onload=function(){

    init();

}

function init(){
    panel1Div = document.getElementById("panel1");
    totalCountInput = document.getElementById("totalCount");
    btn_startButton = document.getElementById("btn_start");
    btn_stopButton = document.getElementById("btn_stop");

    textNode = panel1Div.childNodes[0];

    btn_startButton.addEventListener("click",function(){
        totalCount = totalCountInput.value;
        if( timeID == 0 ){
            timeID = setInterval(getRandomNumber,50);
        }
    });

    btn_stopButton.addEventListener("click",function(){
        if( timeID != 0 ){
            clearInterval(timeID);
            timeID = 0;
            panel1Div.style.color = "red";
            panel1Div.style.fontSize = "200px";

        }
    });
}

function getRandomNumber(){

    color = "#"+parseInt((Math.random()*0xffffff)) .toString(16);
    var fontSize = 20+Math.random()*100;
    var outputNum = Math.floor((1+Math.random()*totalCount));
    panel1Div.innerText = outputNum;
    panel1Div.style.color = color;
    panel1Div.style.fontSize = fontSize+"px";
}